﻿using CommonType;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S_Userinfor.Domains;
using S_UserInfor.Read.Api.Application.Commands;

namespace S_UserInfor.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<UserController> logger;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator"></param>
        public UserController(IMediator mediator, ILogger<UserController> logger)
        {
            _mediator = mediator;
            this.logger = logger;
        }
        [HttpGet]
        public IActionResult Test()
        {
            try
            {
                User info = null;
                info.UName = "test";
                return Ok();
            }
            catch (Exception)
            {
                logger.LogError("执行耿庆杰任务时发生错误");
                throw;
            }
        }

        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="commons"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageResule<User>> PageShowCottage([FromQuery] UserCommands commons)
        {
            return await _mediator.Send(commons);
        } 

        /// <summary>
        /// 用户反填
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<object> FanCity([FromQuery] UserBaCommands command)
        {
            return await _mediator.Send(command);
        }

    }
}
